// pages/type/type.js
var app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        type_data: [],
        skin_style: "",
        is_open: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        app.getSkin();
        wx.request({
            url: "https://news-at.zhihu.com/api/4/themes",
            success: function (res) {
                that.setData({
                    type_data: res.data.others,
                    skin_style: app.globalData.skin,
                    is_open: app.globalData.is_open
                })
                if (app.globalData.skin == "dark") {
                }
            }
        })
    },

    type_details: function (e) {
        let type_id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '../type_lists/type_lists?id=' + type_id,
        });
    },

    skin_change: function (e) {
        var that = this;
        //  如果开启

        if (e.detail.value == true) {
            app.globalData.skin = "dark";
            app.globalData.is_open = true;
        } else {
            app.globalData.skin = "";
            app.globalData.is_open = false;
        }

        // 保存信息
        that.setData({
            skin_style: app.globalData.skin,
            is_open: app.globalData.is_open
        })
        // console.log(that.data.is_open)
        //  保存到本地
        wx.setStorage({
            key: "skin",
            data: app.globalData.skin
        })

        // 同步改变
        wx.setStorageSync('is_open', app.globalData.is_open)

        console.log(app.globalData.is_open)

    }

})